package com.wyix.service.impl;

import com.wyix.entity.User;
import com.wyix.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@Service
public class UserServiceImpl implements UserService {
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    private final List<User> userList = new ArrayList<>();
    private final AtomicInteger idGenerator = new AtomicInteger(1);

    @Override
    public List<User> getAllUsers() {
        logger.info("获取所有用户列表");
        return userList;
    }

    @Override
    public User addUser(User user) {
        user.setId(idGenerator.getAndIncrement());
        userList.add(user);
        logger.info("添加用户，ID: {}", user.getId());
        return user;
    }

    @Override
    public void deleteUser(Integer id) {
        userList.removeIf(u -> u.getId().equals(id));
        logger.info("删除用户，ID: {}", id);
    }
}
